<?php

namespace App;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;

class Club extends Model
{
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name','address','contact_tele','opentime','follow_count','likes_count','intro'
    ];
    public function clubbanners(){
         return $this->hasMany(Clubbanner::class);
    }
    public function clubvideos(){
        return $this->hasMany(Clubvideo::class);
    }
    public function mentors(){
        return $this->hasMany(Mentor::class);
    }
    public function consumers(){
        return $this->belongsToMany(Consumer::class,'clubfollow','club_id','followed_id');
    }
    public function trains(){
        return $this->hasMany(Train::class);
    }
    public function messages(){
        return $this->hasMany(Message::class);
    }
    public function Twitter(){
        return $this->hasMany(Twitter::class);
    }
    public function clubclasses(){
        return $this->hasManyThrough(Clubclass::class,Mentor::class,'club_id','mentor_id','id');
    }
    public function keytodata($keyname){
        return collect($keyname)->map(function($key){

            if(  !is_string($this->$key) && !is_int($this->$key)){
                if(  $this->$key  instanceof Carbon){
                    return [$key=>$this->$key->toFormattedDateString()];
                }
                else{
                        return [$key=>$this->$key->first()['image_url']];

                }

            }

            return [$key=>$this->$key];
        })->collapse()->toArray();



    }
}
